<template>
  <!--    查询栏目-->
    <el-card style="margin: 20px;heignt:70px;">
        <el-form :inline="true" style="margin-top: 10px;">
            <el-form-item style="width: 200px;">
                <el-input placeholder="请输入用id" style="margin-left:30px;" v-model="selectList.userId"></el-input>
            </el-form-item>
            <el-form-item style="width: 200px;">
                <el-input placeholder="请输入车牌号" style="margin-left:30px;" v-model="selectList.license"></el-input>
            </el-form-item>
            <el-form-item style="width: 200px;">
                <el-input placeholder="请输入检查单编号" style="margin-left:30px;" v-model="selectList.id"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="loadList">查询</el-button>
                <el-button type="primary" @click="resetSearch">重置</el-button>
            </el-form-item>
        </el-form>
    </el-card>
  <!--    显示表格信息-->
    <el-card style="margin: 20px;">
        <el-table :data="checlistkArr">
            <el-table-column prop="id" label="检查单编号" align="center"></el-table-column>
            <el-table-column prop="rentalOrderId" label="订单编号" align="center"></el-table-column>
            <el-table-column prop="userId" label="用户名" align="center"></el-table-column>
            <el-table-column prop="license" label="车牌号" align="center"></el-table-column>
            <el-table-column prop="remaker" label="备注信息" align="center"></el-table-column>
            <el-table-column prop="checkTime" label="检查时间" align="center"></el-table-column>
            <el-table-column prop="checkResult" label="检查结果" align="center"></el-table-column>
            <el-table-column label="操作" align="center">
                <template #default="scope">
                    <el-button link type="primary" size="small" @click="editList(scope.row.id)">编辑</el-button>
                    <el-button link type="primary" size="small" @click="delList(scope.row.id,scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </el-card>
<!--      编辑页面弹窗-->

      <el-dialog :title="dialogTitle" v-model="dialogVisable" :before-close="handleClose"
                 style="width:1000px;padding:40px;">
          <el-form label-width="80px" label-position="top">
              <el-row :gutter="20" >
                  <el-col :span="12">
                      <el-form-item label="检查单编号">
                          <el-input v-model="selectList.id" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>
<!--                  <el-col :span="12">
                      <el-form-item label="车牌号" >
                          <el-input v-model="selectList.license" style="width: 800px;" ></el-input>
                      </el-form-item>
                  </el-col>-->
<!--                  <el-col :span="12">
                      <el-form-item label="用户名" >
                          <el-input v-model="selectList.username" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>-->
<!--                  <el-col :span="12">
                      <el-form-item label="订单号">
                          <el-input v-model="selectList.rentalOrderId" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>-->
                  <el-col :span="12">
                      <el-form-item label="车辆外观状况">
                          <el-input v-model="selectList.exteriorCondition" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>
                  <el-col :span="12">
                      <el-form-item label="车辆内饰状况">
                          <el-input v-model="selectList.interiorEquipment" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>
                  <el-col :span="12">
                      <el-form-item label="车辆发动机状况">
                          <el-input v-model="selectList.engineCondition" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>
                  <el-col :span="12">
                      <el-form-item label="车辆轮胎状况">
                          <el-input v-model="selectList.tireCondition" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>
                  <el-col :span="12">
                      <el-form-item label="车辆灯光状况">
                          <el-input v-model="selectList.lightCondition" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>
                  <el-col :span="12">
                      <el-form-item label="车辆检查结果">
                          <el-input v-model="selectList.checkResult" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>
                  <el-col :span="12">
                      <el-form-item label="检查时间">
                          <el-input v-model="selectList.checkTime" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>
                  <el-col :span="12">
                      <el-form-item label="备注信息">
                          <el-input v-model="selectList.remaker" style="width: 800px;"></el-input>
                      </el-form-item>
                  </el-col>
              </el-row>
          </el-form>
          <template #footer>
              <el-button @click="handleClose">取消</el-button>
              <el-button type="primary" @click="updateCheckList">保存</el-button>
          </template>
      </el-dialog>
</template>

<script setup>

import {onMounted, ref} from "vue";
import qs from "qs";
import axios from "axios";
import {ElMessage} from "element-plus";

const  dialogTitle=ref('检查单编辑');
const dialogVisable=ref(false);
//保存查询条件
const selectList = ref({
    id: '',
    userId: '',
    license: '',
    rentalOrderId: '',
    exteriorCondition:'',
    interiorEquipment:'',
    engineCondition:'',
    tireCondition:'',
    lightCondition:'',
    checkResult:'',
    remaker:'',
    checkTime:''
});
//定义数组保存查询数据
const checlistkArr = ref([]);
//加载已完成订单
const loadList = () => {
    let data = qs.stringify(selectList.value);
    console.log(data);
    axios.get(BASE_URL + "/checklist/completed/select?"+ data)
        .then((response) => {
            if (response.data.code == 2000) {
                checlistkArr.value = response.data.data;
                ElMessage.success(response.data.msg)
            } else {
                ElMessage.error(response.data.msg);
            }
        })
}
//页面加载即刻显示
onMounted(() => {
    loadList();
})
//重置用户搜索信息
const resetSearch = () => {
    selectList.value = {};
    loadList();
}
//关闭弹窗
const  handleClose=()=>{
    if (confirm("确定关闭窗口吗？")){
        dialogVisable.value=false;
        selectList.value={};
    }
}

//编辑
const editList = (id) => {
    dialogVisable.value=true;
    selectList.value.id=id;
    let data = qs.stringify(selectList.value);
    axios.get(BASE_URL + "/checklist/completed/select?"+ data)
        .then((response) => {
          if (response.data.code == 2000){
              selectList.value=response.data.data[0];
              ElMessage.success(response.data.msg);
          }else {
              ElMessage.error(response.data.msg);
          }
        })
}

//删除
const delList = (id,row) => {
    console.log(row);
    console.log(id);
    if (confirm("确定删除订单信息吗？")) {
        axios.post(BASE_URL+"/checklist/completed/del/" + id)
            .then((response) => {
                if (response.data.code == 2000) {
                    ElMessage.success(response.data.msg);
                    loadList();
                } else {
                    ElMessage.error(response.data.msg);
                }
            })
    }

}
//保存更新
const updateCheckList = () => {
    dialogVisable.value=false;
    let data=qs.stringify(selectList.value);
    console.log(data);
    axios.post(BASE_URL+"/checklist/completed/update?"+data)
        .then((response)=>{
            if (response.data.code==2000){
                ElMessage.success(response.data.msg);
                selectList.value={};
                loadList();
            }else {
                ElMessage.error(response.data.msg);
            }
        })
}
</script>

<style scoped>

</style>